package org.easybuy.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.easybuy.dao.CommodityCategoryDao;
import org.easybuy.entity.CommodityCategory;
import org.easybuy.service.CommodityCategoryService;
import org.easybuy.serviceimpol.CommdoityCategoryServiceImopl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class CommodityCategoryServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		String parentId = request.getParameter("parentId");
		int pid = Integer.parseInt(parentId);
		PrintWriter out = response.getWriter();
		CommodityCategoryService commodityCategoryService = new CommdoityCategoryServiceImopl();
		List<CommodityCategory> list = new ArrayList<CommodityCategory>();
		List<CommodityCategory> listthreat = new ArrayList<CommodityCategory>();
		list = commodityCategoryService.getAllSecondCategories(pid);
		StringBuffer sb = new StringBuffer();
		int id = 0;
		for (CommodityCategory commodityCategory : list) {
			id = commodityCategory.getId();
			sb.append("<div class=\"zj_l_c\" ><h2>"
					+ commodityCategory.getName() + "</h2>");
			listthreat = commodityCategoryService.getAllthreatCategories(id);
			for (CommodityCategory cgy : listthreat) {
				sb.append("<a href=\"servlet/ProductServlet?ID3="+cgy.getId()+"\" class = \"pdAll\" id = "+cgy.getId()+">" + cgy.getName() + "</a>|");
			}
			sb.append("</div>");
		}
		out.print(sb);
		out.flush();
		out.close();
	}

}
